
    //Angularjs and jquery.datatable with ui.bootstrap and ui.utils

/*    let app=angular.module('formvalid', ['ui.bootstrap','ui.utils']);
    app.controller('validationCtrl',function($scope){
    $scope.data=[
        [
            "123",
            "评论",
            "456",
            "人身攻击"
        ],
        [
            "789",
            "照片",
            "1011",
            "色情"

        ],
        [
            "1213",
            "用户禁言",
            "1415",
            "暴力"
        ]
    ]


    $scope.dataTableOpt = {
    //custom datatable options
    // or load data through ajax call also
    "aLengthMenu": [[10, 50, 100,-1], [10, 50, 100,'All']],
};
});*/

    let app = angular.module('formvalid', ['ui.bootstrap', 'ui.utils']);

    app.controller('validationCtrl', function ($scope, $http, $window) {
        // 在控制器初始化时发送请求获取数据
        $http.get('/getAuditData')
            .then(function (response) {
                // 成功获取数据后，将数据赋值给$scope.data，并添加 decision 属性
                $scope.data = response.data.map(item => ({ ...item, decision: '' }));
            })
            .catch(function (error) {
                console.error('获取数据失败', error);
                alert("获取数据失败");
            });

        $scope.selectedData = [];
        $scope.unselectedData = [];

        $scope.$watch('data', function (newData) {
            // 在数据发生变化时更新未选择数据
            $scope.unselectedData = newData.filter(item => !$scope.selectedData.includes(item));
        }, true);

        $scope.submitForm = function () {
            // 将已选择数据发送给后端
            $http.post('/submitAuditData', $scope.selectedData)
                .then(function (response) {
                    // 成功提交后刷新页面
                    $window.location.reload();
                })
                .catch(function (error) {
                    console.error('提交失败', error);
                });
        };
        $scope.dataTableOpt = {
            //custom datatable options
            // or load data through ajax call also
            "aLengthMenu": [[10, 50, 100, -1], [10, 50, 100, 'All']],
        };
    });


    document.addEventListener("DOMContentLoaded", function() {
        let submitButton = document.querySelector("button[name='reback']");

        submitButton.addEventListener("click", function(event) {
            // 用户点击按钮后，直接跳转到主界面
            window.location.href = "/main";
        });
    });
